﻿//显示悬浮标签
function ShowHiddenText(contentID, sourceClass) {
    $("." + sourceClass).mouseover(function (e) {
        var txt = $(this).text();
        $("#" + contentID).text(txt);
        $("#" + contentID).css({ "position": "fixed", "top": e.pageY + 10, "left": e.pageX }).show();
    });
    $("." + sourceClass).mouseout(function () {
        $("#" + contentID).hide();
    });
}

//获取url参数
function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

//判断是否整数
function checkNum(val) {
    var reg = /^[0-9]+$/;
    if (!reg.test(val)) {
        return false;
    }
    return true;
}


//刷新主表格
function RefreshTable(obj) {
    var headData = obj.HeadMsg;
    var dtable = document.getElementById("mtable");
    var headInfos = document.getElementById("mhead");

    if (headInfos != null) {
        dtable.removeChild(headInfos);
    }
    infos = document.createElement("tbody");
    infos.setAttribute("id", "mbody");

    headInfos = document.createElement("thead");
    headInfos.setAttribute("id", "mhead");


    var i = 5;

    var j = headData.length;

    var colCount = i + j;

    var tr = document.createElement("tr");
    tr.className = "tfNiceTable_head_style";

    var td1 = document.createElement("td");
    var td2 = document.createElement("td");
    var td3 = document.createElement("td");
    var td4 = document.createElement("td");
    var td5 = document.createElement("td");
    var td6 = document.createElement("td");

    td1.innerHTML = "ID";
    td2.innerHTML = "流水号";
    td3.innerHTML = "号牌号码";
    td4.innerHTML = "是否上线";

    tr.appendChild(td1);
    tr.appendChild(td2);
    tr.appendChild(td3);
    tr.appendChild(td4);

    for (var t = 0; t < headData.length; t++) {
        var td = document.createElement("td");
        td.innerHTML = headData[t].STA_NAME;
        tr.appendChild(td);
    }

    td5.innerHTML = "是否上传总结论";
    td6.innerHTML = "";
    tr.appendChild(td5);
    tr.appendChild(td6);
    headInfos.appendChild(tr);
    dtable.appendChild(headInfos);

    var data = obj.Msg;
    var infos = document.getElementById("mbody");
    if (infos != null) {
        dtable.removeChild(infos);

    }
    infos = document.createElement("tbody");
    infos.setAttribute("id", "mbody");
    if (data.length != 0) {
        for (var i = 0; i < data.length; i++) {
            var tr = document.createElement("tr");

            var td1 = document.createElement("td");
            var td2 = document.createElement("td");
            var td3 = document.createElement("td");
            var td4 = document.createElement("td");
            var td5 = document.createElement("td");
            var td6 = document.createElement("td");
            td1.innerHTML = data[i].ID;
            td2.innerHTML = data[i].JCLSH;
            td3.innerHTML = data[i].HPHM;
            td4.innerHTML = data[i].IS_LOGIN;
            tr.appendChild(td1);
            tr.appendChild(td2);
            tr.appendChild(td3);
            tr.appendChild(td4);
            for (var x = 0; x < j; x++) {
                td = document.createElement("td");
                if (data[i].JCZT_STATUS == 4 || data[i].JCZT_STATUS == 3) {
                    td.innerHTML = "已检";
                    td.bgColor = "white";
                }
                else {
                    var obj = SetCheckText(data[i].GWBH, x);
                    td.innerHTML = obj.txt;
                    td.bgColor = obj.color;
                }
                tr.appendChild(td);
            }
            td5.innerHTML = data[i].IS_UPLOAD;
            td6.innerHTML = "<span  onclick=GetResult('" + data[i].JCLSH + "','"+data[i].AJLSH + "','" + data[i].HPHM + "');>详情</span>";//+ "丨" + "<span   onclick=TBBusiness('" + data[i].JCLSH + "');>退办</span>";
            tr.appendChild(td5);
            tr.appendChild(td6);
            infos.appendChild(tr);
        }
        dtable.appendChild(infos);
    }
}

//设置检测状态的文字
function SetCheckText(val, i) {

    var obj = new Object();
    obj.txt = "";
    obj.color = "white"

    if (val > i) {
        obj.txt = "已检";
        obj.color = "#7CFC00";
    }
    else if (val == i) {
        obj.txt = "在检";
        obj.color = "yellow";
    }
    else {
        obj.txt = "";
        obj.color = "white"
    }
    return obj;
}



var allowSearchMsg = 1;
function GetResult(JCLSH,AJLSH, HPHM) {
    var obj;

    if (allowSearchMsg == 1) {
        allowSearchMsg = 0;
        console.log(11);
        $.ajax({
            type: 'POST',
            url: 'AjaxClassForDD.ashx',
            dataType: 'text',
            data: { Action: 'GetDDInfo', AJLSH: JCLSH },
            success: function (data) {
                if (data != "RequestError") {
                    obj = eval('(' + data + ')');
                    ShowJKMsg(obj, HPHM,AJLSH);
                }
                else {
                    console.log(data);
                }
            },
            complete: function () {
                allowSearchMsg = 1;
            }
        });
    }
}


function GetIPStr()
{
    var ipStr;
    $.ajax({
        type: 'POST',
        url: '../Tools/AjaxClassTool.ashx',
        dataType: 'text',
        data: { Action: 'getipstr' },
        async: false,
        success: function (data) {
        
            ipStr = data;
        },
        complete: function () {
         
        }
    });
    return ipStr;
}

//退办
var markTB = 1;
function TBBusiness(JCLSH) {
    layer.confirm('确定要退办流水号为:' + JCLSH + '的业务吗?', {
        btn: ['确定', '取消']
    }, function (index) {

        if (markTB == 1) {
            markTB = 0;
            layer.load();
            $.ajax({
                type: 'POST',
                url: 'AjaxClassForDD.ashx',
                dataType: 'text',
                data: { Action: 'TBBusiness', JCLSH: JCLSH },
                success: function (data) {
                    var obj = eval('(' + data + ')');
                    if (obj.Success == '1') {
                        layer.msg('退办成功！', { icon: 1 });
                    }
                    else {
                        layer.msg('退办失败,' + obj.Msg, { time: 5000 });
                    }
                },
                complete: function () {
                    markTB = 1;
                    layer.closeAll('loading');
                }
            });
        }
    }, function () { });
}

//显示接口详细信息
var isOpen = 1;
function ShowJKMsg(obj, HPHM,AJLSH) {
    if (isOpen) {
        isOpen = 0;
        var data = obj.DataInfo;
        var dtable = document.getElementById('tJKMsgTable');
        var infos = document.getElementById('tJKMsgBody');
        if (infos != null) {
            dtable.removeChild(infos);
        }
        console.log(obj);
        infos = document.createElement('tbody');
        infos.setAttribute('id', 'tJKMsgBody');
        for (var i = 0; i < data.length; i++) {
            var tr = document.createElement('tr');
            var td1 = document.createElement('td');
            var td = document.createElement('td');
            var td2 = document.createElement('td');
            var td3 = document.createElement('td');
            var td4 = document.createElement('td');
            td1.innerHTML = data[i].JKType;
            td.innerHTML = "<a class='showDiv'>" + data[i].JYXM + "</a>";
            td2.innerHTML = data[i].DateStr;
            if (data[i].Suc == 1) {
                td3.innerHTML = "是";
            }
            else {
                td3.innerHTML = "<a  href='###' style='color:red'>否</a>";
                console.log(data.RowId);
            }
            td4.innerHTML = "<a  href='###' ondblclick='EmptyClick()' onclick=OpenNewWindow('" + data[i].RowId + "') style='color:blue'>详情</a>";
            tr.appendChild(td1);
            tr.appendChild(td);
            tr.appendChild(td2);
            tr.appendChild(td3);
            tr.appendChild(td4);
            infos.appendChild(tr);

        }
        dtable.appendChild(infos);

        layer.open({
            type: 1,
            title: "联网流水号：" + AJLSH + "  号牌号码：" + HPHM,
            shadeClose: true,
            area: ['800px', '520px'],
            content: $('#dJKMsg')
        });
        ShowHiddenText('showTxt', 'showDiv');
        isOpen = 1;
    }
}

//显示详细信息
function OpenNewWindow(rowId) {
    var url = "NET_AJ_JK_RESULT_Insert_Update.aspx?m=r&UniqueKey=" + rowId;
    layer.open({
        type: 2,
        title: "详细信息",
        shadeClose: true,
        maxmin: true,
        area: ['800px', '520px'],
        content: url
    });
}